package jxc.servlet.sale;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import jxc.data.hibernate.dao.GoodsDAO;
import jxc.data.hibernate.pojo.Goods;

/**
 * Servlet implementation class ChooseGood
 */
@WebServlet("/sale/chooseGood")
public class ChooseGood extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public ChooseGood() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		String name=request.getParameter("name");
		String gid=request.getParameter("id");
		GoodsDAO dao=new GoodsDAO();
		List<Goods> goods=null;
		if(gid!=null&&gid.length()>0){
			//根据商品编号查找
			goods=new ArrayList<Goods>();
			Goods good=dao.getById(gid);
			if(good!=null)
				goods.add(good);
		}else if(name!=null&&name.length()>0){
			goods=dao.getLikeName(name);
		}
		request.setAttribute("goods", goods);
		request.getRequestDispatcher("/sale/goodsList.jsp").forward(request, response);
	}

}
